﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ART.Common;

namespace ART.Admini
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Loginfrm.Attributes.Add("onSubmit", "return CheckInput(this)");
               
            }
            //qv/r7OxWD+xm518kBiIk/6TgdpbSrpof7jcHw/j9k3M=
            //base.Response.Write(Utils.SHA256("admin888"));
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string txtUser = AdminName.Text;
            string txtpwd = Password.Text;
           // string txtrnd = CheckCode.Text;
            if (txtUser.Length < 1 || txtpwd.Length < 1)
            {
                Response.Write("<script defer>window.alert('用户名，密码不能空！');top.location='login.aspx';</script>");
                Response.End();
            }
            //if (base.Request.Cookies["RndCode"] != null)
            //{
            //    if (string.Compare(JSecury.Encrypt(txtrnd), base.Request.Cookies["RndCode"].Value, true) != 0)
            //    {
            //        CheckCode.Text = "";
            //        base.Response.Write("<script>alert('验证码不对，请核实在登录');location.href='" + base.Request.Url.ToString() +
            //                            "';</script>");

            //    }
            //}
            switch (BLL.B_TBAdmin.Logined(txtUser.Trim(), Utils.SHA256(txtpwd.Trim())))
            {
                case -1:
                    MessageBox.Alert(sender, "用户名/密码错误!");
                    return;

                case 0:
                    MessageBox.Alert(sender, "账号未启用!");
                    return;

                case 1:
                    base.Response.Redirect("Default.aspx");
                    return;

                case 2:
                    MessageBox.Alert(sender, "您的账号已经在别处登录!");
                    return;

                case 3:
                    MessageBox.Alert(sender, "请确保主机已经连接互联网!");
                    return;
            }

        }
    }
}

